package Control;
/**
 *
 * @author zhaoyingxi
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import model.Order;
import util.JdbcUtil;

public class OrderControl {
	public static void insert(Order order){
		boolean result = false;
		Connection connection = JdbcUtil.getConnection();
		String sql = "INSERT INTO ordertable(airLineNum,userName,num,bankAccount,soldPrice) values (?,?,?,?,?) ";
		PreparedStatement statement = null;
		try {
			connection.setAutoCommit(false);
			statement = connection.prepareStatement(sql);
			statement.setString(1, order.getAirLineNum());
			statement.setString(2, order.getUserName());
			statement.setString(3, order.getNum()+"");
			statement.setString(4, order.getBankAccount());
			statement.setString(5, order.getSoldPrice());
			statement.executeUpdate();
			connection.commit();
			result=true;
		} catch (Exception e) {
			try {
				connection.rollback();
			} catch (SQLException e1) {
				//Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
		finally{
			JdbcUtil.closeConnection();
		}
	}
}

